﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilmManagement2.Founction;
using System.Data;
using System.Data.SqlClient;

namespace FilmManagement2.WebPage
{
    public partial class BookPage_2 : System.Web.UI.Page
    {
        public static bool st1 = false;
        public static bool st2 = false;
        public static bool st3 = false;
        public static bool temp = false;
        protected void Page_Load(object sender, EventArgs e)
        {
           string starttime=Session["SelectTime"].ToString();
           int filmid = Convert.ToInt32(Session["FilmId"]);
           DataSet ds=new DataSet();
           ConnectToSql cts = new ConnectToSql();
           ds=cts.GetFilmByID(2);
           starttimelbl.Text = starttime;
           filmnamelbl.Text = ds.Tables[0].Rows[0][1].ToString();
           filmdet.Text = ds.Tables[0].Rows[0][3].ToString();
           string path = ds.Tables[0].Rows[0][4].ToString();
           path = path.Substring(40);
           path = "~" + path.Replace(@"\", @"/");
           filmimge.ImageUrl = path;
           SeatDetail sd = new SeatDetail();
           if (sd.getseatOne(filmid, Convert.ToDateTime(starttime)) > 0)
           {
               studio1but.Visible = true;

           }
           if (sd.getseatTwo(filmid, Convert.ToDateTime(starttime)) > 0)
           {
               studio2but.Visible = true;
           }
           if (sd.getseatThree(filmid, Convert.ToDateTime(starttime)) > 0)
           {
               studio3but.Visible = true;
           }
           ConnectToSql cts2 = new ConnectToSql();
           DataSet ds2 = cts2.GetFilmByID(filmid);
            pricelbl2.Text = ds2.Tables[0].Rows[0][5].ToString();

        }
        protected void admin_Click(object sender, EventArgs e)
        {

            if (submit.Visible == false)
            {
                submit.Visible = true;
                accountlbl.Visible = true;
                txtAccount.Visible = true;
                passwordlbl.Visible = true;
                txtPassword.Visible = true;
            }
            else
            {
                submit.Visible = false;
                accountlbl.Visible = false;
                txtAccount.Visible = false;
                passwordlbl.Visible = false;
                txtPassword.Visible = false;
            }

        }

    

        protected void bookticketbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"BookPage_1.aspx");
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            ConnectToSql cts = new ConnectToSql();
            if (cts.AdminLog(txtAccount.Text, txtPassword.Text))
            {
                Session["AdminName"] = txtAccount.Text;
                Response.Redirect(@"AdminPage.aspx");
            }
            else
            {
                Response.Write("<script>alert('登陆失败')</script>");

            }

        }

        protected void hombut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"MainPage.aspx");
        }

        protected void bookticketbut_Click1(object sender, EventArgs e)
        {
            Response.Redirect(@"BookPage_1.aspx");
        }

        protected void suggestbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"SuggestionPage.aspx");
        }

        protected void studio1but_Click(object sender, EventArgs e)
        {
            seatlist.Items.Clear();
            ConnectToSql cts = new ConnectToSql();
                     st1 = true;
                     st2 = false;
                     st3 = false;
                     temp = true;
                       
            
           DataSet ds=cts.GetStudioOneDetailByIDandStartTime(Convert.ToInt32(Session["FilmId"].ToString()), Convert.ToDateTime(Session["SelectTime"].ToString()));
           for (int i = 4; i <= 12;i++ )
               if ( Convert.ToBoolean(ds.Tables[0].Rows[0][i]))
               {
                   if (i == 4)
                   {
                       seatlist.Items.Add("AA");
                   }
                   if (i == 5)
                   {
                       seatlist.Items.Add("AB");
                   }

                   if (i == 6)
                   {
                       seatlist.Items.Add("AC");
                   }
                   if (i == 7)
                   {
                       seatlist.Items.Add("BA");
                   }

                   if (i == 8)
                   {
                       seatlist.Items.Add("BB");
                   }
                   if (i == 9)
                   {
                       seatlist.Items.Add("BC");

                   }
                   if (i == 10)
                   {
                       seatlist.Items.Add("CA");
                   }

                   if (i == 11)
                   {
                       seatlist.Items.Add("CB");
                   }
                   if (i == 12)
                   {
                       seatlist.Items.Add("CC");
                   }
               }
        }

        protected void studio2but_Click(object sender, EventArgs e)
        {
            seatlist.Items.Clear();
            st1 = false;
            st2 = true;
            st3 = false;
            temp = true;
            ConnectToSql cts = new ConnectToSql();

            DataSet ds = cts.GetStudioTwoDetailByIDandStartTime(Convert.ToInt32(Session["FilmId"].ToString()), Convert.ToDateTime(Session["SelectTime"].ToString()));
            for (int i = 4; i <= 12; i++)
                if (Convert.ToBoolean(ds.Tables[0].Rows[0][i]))
                {
                    if (i == 4)
                    {
                        seatlist.Items.Add("AA");
                    }
                    if (i == 5)
                    {
                        seatlist.Items.Add("AB");
                    }

                    if (i == 6)
                    {
                        seatlist.Items.Add("AC");
                    }
                    if (i == 7)
                    {
                        seatlist.Items.Add("BA");
                    }

                    if (i == 8)
                    {
                        seatlist.Items.Add("BB");
                    }
                    if (i == 9)
                    {
                        seatlist.Items.Add("BC");

                    }
                    if (i == 10)
                    {
                        seatlist.Items.Add("CA");
                    }

                    if (i == 11)
                    {
                        seatlist.Items.Add("CB");
                    }
                    if (i == 12)
                    {
                        seatlist.Items.Add("CC");
                    }
                }
        }

        protected void studio3but_Click(object sender, EventArgs e)
        {
            seatlist.Items.Clear();
            st1 = false;
            st2 = false;
            st3 = true;
            temp = true;
            ConnectToSql cts = new ConnectToSql();

            DataSet ds = cts.GetStudioThreeDetailByIDandStartTime(Convert.ToInt32(Session["FilmId"].ToString()), Convert.ToDateTime(Session["SelectTime"].ToString()));
            for (int i = 4; i <= 12; i++)
                if (Convert.ToBoolean(ds.Tables[0].Rows[0][i]))
                {
                    if (i == 4)
                    {
                        seatlist.Items.Add("AA");
                    }
                    if (i == 5)
                    {
                        seatlist.Items.Add("AB");
                    }

                    if (i == 6)
                    {
                        seatlist.Items.Add("AC");
                    }
                    if (i == 7)
                    {
                        seatlist.Items.Add("BA");
                    }

                    if (i == 8)
                    {
                        seatlist.Items.Add("BB");
                    }
                    if (i == 9)
                    {
                        seatlist.Items.Add("BC");

                    }
                    if (i == 10)
                    {
                        seatlist.Items.Add("CA");
                    }

                    if (i == 11)
                    {
                        seatlist.Items.Add("CB");
                    }
                    if (i == 12)
                    {
                        seatlist.Items.Add("CC");
                    }
                }
        }

        protected void submitbut_Click(object sender, EventArgs e)
        {
            if (temp)
            {
                if (seatlist.SelectedItem!=null)
                {
                    Session["Seat"] = seatlist.SelectedItem.ToString();
                    Session["StartTime"] = starttimelbl.Text;
                    Session["Price"] = pricelbl2.Text;
                    if (st1)
                    {
                        Session["StudioNumber"] = "One";
                    }
                    if (st2)
                    {
                        Session["StudioNumber"] = "Two";
                    }
                    if (st3)
                    {
                        Session["StudioNumber"] = "Three";
                    }
                    Response.Redirect(@"BookPage_3.aspx");
                }
                else
                {
                    Response.Write("<script>alert('请选择您的座位，如果座位都为空，请更换电影或更换时间，谢谢！')</script>");
                }
            }
            else
            {

                Response.Write("<script>alert('请选择您要在几号放映厅观看')</script>");
            }
        }

      

       
    }
}